package com.blog.utils;

import com.blog.constant.ErrorConstant;
import com.blog.vo.ResultVo;

/**
 * 返回数据工具类
 *
 * @author wmb
 *
 * @since 2021-2-7
 */
public class ResultVoUtil {

    private static final String SUCCESS = "success";

    public ResultVoUtil() {
    }

    /**
     * 成功
     *
     * @param data 需要返回的数据
     *
     * @return data
     */
    public static ResultVo success(Object data) {
        ResultVo result = new ResultVo();
        result.setCode(0);
        result.setMessage(SUCCESS);
        result.setData(data);
        return result;
    }

    /**
     * 成功
     *
     * @return 返回空
     */
    public static ResultVo success() {
        return success(null);
    }

    /**
     * 错误
     *
     * @param errorConstant 错误枚举类
     *
     * @return 错误信息
     */
    public static ResultVo error(ErrorConstant errorConstant) {
        ResultVo result = new ResultVo();
        result.setCode(errorConstant.getErrorCode());
        result.setMessage(errorConstant.getErrorMsg());
        return result;
    }

    /**
     * 带返回数据的错误
     *
     * @param code 状态码
     * @param errorMsg 消息
     *
     * @return ResultBean
     */
    public static ResultVo error(Integer code, String errorMsg, Object data) {
        ResultVo result = new ResultVo();
        result.setCode(code);
        result.setMessage(errorMsg);
        result.setData(data);
        return result;
    }

    /**
     * 错误
     *
     * @param code 状态码
     * @param errorMsg 消息
     *
     * @return ResultBean
     */
    public static ResultVo error(Integer code, String errorMsg) {
        ResultVo result = new ResultVo();
        result.setCode(code);
        result.setMessage(errorMsg);
        return result;
    }

    /**
     * 错误
     *
     * @param errorMsg 消息
     *
     * @return ResultBean
     */
    public static ResultVo error(String errorMsg) {
        ResultVo result = new ResultVo();
        result.setCode(9999);
        result.setMessage(errorMsg);
        return result;
    }

}
